<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>添加学生信息</title>

		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
       <script type='text/javascript'
			src='<%=request.getContextPath()%>/js/sorttable.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/N13FormValidation-2.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dWRCollegeMajorAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dormitoryAllocateAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/apartmentViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentLodgeMgrAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentAction.js'></script>		
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jqueryCopyEvent.js"></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jquery.corner.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		
			
		<script type='text/javascript'>
		
	     function isExistStuNo(){
			var result = false;
			var isExistStuNoCallback = function isExistStuNoCallbackFunc(count){
				if(count != 0){
					return result = true;
				}else{
					return result = false;
				}
			}
			DWREngine.setAsync(false);
			var a = studentAction.isExistStu($('studentno').value,"sno",isExistStuNoCallback);
			return !result;
		}
	
		
		//=========================页面初始化=====================
		 $j(function(){
		 	showAllCollege( $j("#collegeinfoid").get(0));//学院列表
		 	showAllMajor($j("#majorinfoid").get(0));//专业列表		 
		 });
     //-----------------------页面初始化结束-------------------	
     
     	
		//显示所有的学院
		function showAllCollege(collegeObj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction.getAllCollegeInfo(function (collegeList){
					if(null == collegeList){
						return;
					}
					var collegeInfo =collegeList;
					var s =collegeObj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限学院",'0');
			 		for ( var i = 1; i < collegeList.length+1; i++) {
						var opt = new Option(collegeList[i-1].collegeinfoname,
								collegeList[i-1].collegeinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		
//显示所有的专业,obj为显示下拉列表元素
		function showAllMajor(obj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction. getAllMajorInfo(function (majorList){
					if(null == majorList){
						return;
					}
					var majorInfo =majorList;
					//alert(aptValue[0].apartmentfloornum);
					var s = obj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限专业",'0');
						//alert(majorList[0].majorinfoname)
					for ( var i = 1; i < majorList.length+1; i++) {
						var opt = new Option(majorList[i-1].majorinfoname,
								majorList[i-1].majorinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		//选择的学院变动的时候，专业联动 
		function selectedCollegeChange(collegeObj){
			majorObj = $j("#majorinfoid").get(0);
			if(collegeObj.options[collegeObj.selectedIndex].value == '0'){
				showAllMajor(majorObj);
				return;
			}
			showMajorByCollegeinfoid(collegeObj,collegeObj.options[collegeObj.selectedIndex].value);
			
		}
		//根据学院显示所有的专业
		function showMajorByCollegeinfoid(obj,collegeinfoid){
			dWRCollegeMajorAction.getMajorInfoByCollegeId(collegeinfoid, function  (majorList){
				var s =$j("#majorinfoid").get(0);
				if(majorList == null){
					DWRUtil.removeAllOptions(s); 
					s.options[0] = new
					 Option("不存在专业",'0');
					return;
				}
				var majorInfo =majorList;
				//alert(aptValue[0].apartmentfloornum);
				 	DWRUtil.removeAllOptions(s);  
					s.options[0] = new Option("不限专业",'0');
					//alert(majorList[0].majorinfoname)
				for ( var i = 1; i < majorList.length+1; i++) {
					var opt = new Option(majorList[i-1].majorinfoname,
							majorList[i-1].majorinfoid);
					s.options[i] = opt;
				}
			});
			
		}
		//选择的专业变动的时候，学院联动
		function selectedMajorChange(obj){
			major = obj;
			if(obj.options[obj.selectedIndex].value == '0'){
				return;
			}
			showCollegeByMajorInfoid(obj,obj.options[obj.selectedIndex].value);
		}
		//根据专业显示学院
		function showCollegeByMajorInfoid(obj,majorinfoid){
			dWRCollegeMajorAction.getCollegeInfoByMajorId(majorinfoid,function (collegeList){
				var college = $j("#collegeinfoid").get(0);
				for(var a=0;a<college.options.length;a++){
					if(college.options[a].value == collegeList[0].collegeinfoid){
						college.options[a].selected = "selected";
						break;
					}
				}
			});
		}
		</script>
	</head>

	<body>
	<div id="page_container">
		<jsp:include page="studentnav.jsp"></jsp:include>
		<h2>添加学生信息</h2>
			<s:form action="insertstudent.action" enctype="multipart/form-data" method="POST"
				id="insertstudent" theme="simple" >
				
				<s:hidden name="student.studentind" value="1" />
				<table class="table_common">
					<tr>
						<td class="td_left">
							学号：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentno" id="studentno" ></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							选择学生照片：
						</td>						
						<td class="td_right">
							<s:file name="uploadedFile"></s:file>
						</td>
					</tr>
					
					
					<tr>
						<td class="td_left">
							姓名：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentname" id="studentname"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							性别：
						</td>
						<td class="td_right">
							<s:radio name="student.studentgender" list="#{'男':'男','女':'女'}"
								value="'男'" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							出生日期：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentbirthday " id="studentbirthday"></s:textfield>
							格式：YYYY-MM-DD
						</td>
					</tr>
					
					<tr>
						<td class="td_left">
							政治面貌：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select" name="student.studentpolitics"
								list="#{'党员':'党员','预备党员':'预备党员','团员':'团员','群众':'群众','其他':'其他'}"
								value="'本科'" required="true" cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							身份证号：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentidentitycardno"
								id="studentidentitycardno"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							生源地：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentbirthplace"
								id="studentbirthplace"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							民族：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentethnic" id="studentethnic"></s:textfield>
						</td>
					</tr>
					
					<tr>
					<td class="td_left">
					        学院:
					 </td>
					 <td class="td_right">
					<select  name="student.collegeinfoid" id="collegeinfoid" style="width: 153px;" onchange="selectedCollegeChange(this)" >
					</select>
					</td>
					</tr>
					<tr>
					<td class="td_left">
					 	专业:
					 </td>
					 <td class="td_right">
					<select  name="student.majorinfoid" id="majorinfoid" style="width: 153px;" onchange="selectedMajorChange(this)">
					</select>
					</td>
					</tr>
					
					<tr>
					<td class="td_left">
					班级:
					</td>
					<td class="td_right">
					<s:textfield name="student.studentclass" id="studentclass"></s:textfield>
					</td>
					</tr>
					
					
				
					<tr>
						<td class="td_left">
							学生类型：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select" name="student.studenttype"
								list="#{'预科':'预科','本科':'本科','硕士研究生':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true" cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							招生类别：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentenrolltype"
								list="#{'预科':'预科','本科':'本科','硕士研究生':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							学制：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studenteducationyears"
								list="#{'4':'4年制','5':'5年制','3':'2.5年制'}" value="'4'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							录取类别：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentadmissiontype"
								list="#{'预科':'预科','本科':'本科','硕士研究生':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true"  cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							入学年份：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentenrollyear"
								list="#{'2003':'2003','2004':'2004','2005':'2005','2006':'2006','2007':'2007','2008':'2008','2009':'2009'}"
								value="'2009'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							联系电话：
						</td>
						<td class="td_right">
							<s:textfield name="student.studenttelephone"
								id="studenttelephone"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							通信地址：
						</td>
						<td class="td_right">
							<s:textfield name="student.studenthomeaddress"
								id="studenthomeaddress"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							档案所在地：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentarchivesaddress"
								id="studentarchivesaddress"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							备注：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentmisc" id="studentmisc"></s:textfield>
						</td>
					</tr>
				</table>
				<s:submit cssClass="common_button" id="formSub" value="提交"></s:submit>
			</s:form>
		</div>
		<script type="text/javascript">
			N13.register('insertstudent',[
					
					{
						id:'studentno',
						type:'Required',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					{
						id:'studentno',
						type:'custom',
						validMsg:'√',
						invalidMsg:'学号已存在,请重新输入',
						customFunc: isExistStuNo,
						validOnBlur:true,
						renderValid:true
					},
					
					{
						id:'studentname',
						type:'Required', 
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					//{
					//	id:'studentbirthday',
					//	type:'format',
					//	validMsg:'√',
					//	validOnBlur:true,
					//	renderValid:true,
					//	pattern: /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/i
					//},
					
				//	{
				//		id:'studentidentitycardno',
				//		type:'Required',
				//		validMsg:'√',
				//		validOnBlur:true,
				//		renderValid:true
				//	},
					//{
				//		id:'studenttelephone',
				//		type:'format',
				//		validMsg:'√',
				//		validOnBlur:true,
				//		renderValid:true,
				//		pattern: /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i
				//	}
					
				]);
			window.onload = function(){
				var nav_a=$j('#page_nav a');
				var nav_span=$j("#page_nav a span");
				for(var u = 0 ;u<nav_a.length;u++){
						nav_a.get(u).style.backgroundPosition="left top";
						nav_span.get(u).style.backgroundPosition="right top";							
				}
				$j('#page_nav a').get(0).style.backgroundPosition="0% -42px";
				$j("#page_nav a span").get(0).style.backgroundPosition="100% -42px";
			}	
			</script>
	</body>
</html>
					